package com.softeem.service.impl;

import com.softeem.bean.User;
import com.softeem.dao.UserDao;
import com.softeem.dao.impl.UserDaoImpl;
import com.softeem.service.UserService;

import java.sql.SQLException;

//业务层[服务层]
public class UserServiceImpl implements UserService {
    private UserDao userDao = new UserDaoImpl();

    /**
     * 注册用户
     * @param user
     */
    @Override
    public void registUser(User user)throws SQLException {
        userDao.saveUser(user);
    }

    /**
     * 用户登录
     * @param user
     * @return
     */
    @Override
    public User login(User user)throws SQLException {
        return userDao.queryUserByUsernameAndPassword(user.getUsername(),user.getPassword());
    }

    /**
     * 检查用户名是否可用
     * @param username
     * @return 如果返回true表示用户名可以使用,如果返回false表示用户不能使用
     */
    @Override
    public boolean existsUsername(String username)throws SQLException {
        return userDao.queryUserByUsername(username)==null;
    }
}
